package aiku.numericalcontroloa.Controller.Devices;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.DevicesReturnDto;
import aiku.numericalcontroloa.Model.Entity.Devices;
import aiku.numericalcontroloa.Model.Entity.DevicesReturn;
import aiku.numericalcontroloa.Service.DevicesReturnService;
import aiku.numericalcontroloa.Service.Impl.DevicesReturnServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author 马文杰
 * @version 1.0
 */
@RestController
@RequestMapping("/devicesReturn")
public class DevicesReturnController {
    @Autowired
    private DevicesReturnServiceImpl devicesReturnService;
    /**
     * 查询当前用户借出的设备
     */
    @PostMapping("/UserSelectList")
    public Result UserSelectList() {
        return devicesReturnService.UserSelectList();
    }

    /**
     * 通过借出id查询设备信息
     */
    @PostMapping("/selectReturnById")
    public Result selectById(@RequestParam("returnId") String returnId) {
        return devicesReturnService.selectReturnById(returnId);
    }

    /**
     * 管理分页查询所有用户借出设备
     */
    @PostMapping("/selectPageList")
    public Result selectPageList(@RequestParam("page") Integer page, @RequestParam("size") Integer size,@RequestParam("status") String status) {
        return devicesReturnService.selectPageList(page, size,status);
    }

    /**
     * 管理通过模糊查询所有用户借出设备,通过名称,型号,借出人
     */
    @PostMapping("/selectLikeName")
    public Result selectList(@RequestParam("name") String name) {
        return devicesReturnService.selectLikeName(name);
    }


    /**
     * 管理审核设备归还
     */
    @PostMapping("/adminCheckReturn")
    @Transactional  //添加事务
    public Result adminCheckReturn(@RequestParam("returnId") String returnId,@RequestParam("status") String status) {
        Result result = devicesReturnService.adminCheckReturn(returnId,status);
        return result;
    }

    /**
     * 管理修改设备信息
     */
    @PostMapping("/adminUpdateDevice")
    public Result adminUpdateDevice(@RequestBody DevicesReturn devicesReturn) {
        Result result = devicesReturnService.adminUpdateDevice(devicesReturn);
        return result;
    }

    /**
     * 获取归还列表
     * @param devicesReturnDto
     * @return
     */
    @PostMapping("/getDevicesReturnList")
    public Result getDevicesReturnList(@RequestBody DevicesReturnDto devicesReturnDto){
        return devicesReturnService.getDevicesReturnList(devicesReturnDto);
    }

    /**
     * 申请归还设备
     * @param devicesReturnDto
     * @return
     */
    @PostMapping("/addDevicesReturn")
    public Result addDevicesReturn(@RequestBody DevicesReturnDto devicesReturnDto){
        return devicesReturnService.addDevicesReturn(devicesReturnDto);
    }

    /**
     * 审核归还设备申请
     * @param devicesReturnDto
     * @return
     */
    @PostMapping("/examineDevicesReturn")
    public Result examineDevicesReturn(@RequestBody DevicesReturnDto devicesReturnDto){
        return devicesReturnService.examineDevicesReturn(devicesReturnDto);
    }
    /**
     * 删除归还记录
     * @param devicesReturnDto
     * @return
     */
    @PostMapping("/deleteReturn")
    public Result deleteReturn(@RequestBody DevicesReturnDto devicesReturnDto){
        return devicesReturnService.deleteReturn(devicesReturnDto);
    }

}
